<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="./lib/dist/include-openlayers-local.js"></script>
    <title>Document</title>
  </head>
  <body>
    <div id="map"></div>
    <script>
      var data = {
        type: 'FeatureCollection',
        features: [
          {
            type: 'Feature',
            geometry: {
              type: 'Point',
              coordinates: [114, 30]
            }
          },
          {
            type: 'Feature',
            geometry: {
              type: 'LineString',
              coordinates: [
                [114, 30],
                [120, 30]
              ]
            }
          }
        ]
      }
      const style = new ol.style.Style({
        //填充色
        fill: new ol.style.Fill({
          color: 'rgba(255, 255, 255, 0.2)'
        }),
        //边线颜色
        stroke: new ol.style.Stroke({
          color: '#ffcc33',
          width: 2
        }),
        //形状
        image: new ol.style.Circle({
          radius: 8,
          fill: new ol.style.Fill({
            color: '#ffcc3367'
          }),
          stroke: new ol.style.Stroke({
            color: '#333',
            width: 2
          })
        })
      })
      var source = new ol.source.Vector({
        /* 将geojson数据设置给实例数据源 */
        features: new ol.format.GeoJSON().readFeatures(data)
      })
      var layer = new ol.layer.Vector({
        source,
        style
      })
      const gaodeMapLayer = new ol.layer.Tile({
        title: '高德地图',
        source: new ol.source.XYZ({
          url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
          wrapX: false
        })
      })
      const map = new ol.Map({
        target: 'map',
        view: new ol.View({
          projection: 'EPSG:4326',
          center: [114, 30],
          zoom: 6
        }),
        layers: [gaodeMapLayer,layer]
      })
      const source2 = new ol.source.Vector({
        url: './1.geojson',
        format: new ol.format.GeoJSON()
      })
      const layer2 = new ol.layer.Vector({
        source: source2,
        style
      })
      map.addLayer(layer2)
      const source1 = new ol.source.Vector({
        url: 'https://geo.datav.aliyun.com/areas_v3/bound/geojson?code=510000_full',
        format: new ol.format.GeoJSON()
      })
      const layer1 = new ol.layer.Vector({
        source: source1
      })
      map.addLayer(layer1)
    </script>
  </body>
</html>
